<template>
    <div>
        <!-- 面包屑 -->
        <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>权限管理</el-breadcrumb-item>
        <el-breadcrumb-item>权限列表</el-breadcrumb-item>
        </el-breadcrumb>

        <!-- 卡片视图 -->
        <el-card>
        <el-button type="primary"
                    @click="addDialogVisible = true">添加角色</el-button>
        <!-- 角色列表区域 -->
        <el-table :data="rolesList"
                    stripe
                    border>
            <!-- 展开列 -->
            <el-table-column type="expand">
            <template slot-scope="scope">
                <el-row :class="['bdbottom',i1 === 0 ? 'bdtop':'','vcenter']"
                        v-for="(item1,i1) in scope.row.children"
                        :key="item1.id">
                <!-- 渲染一级权限 -->
                <el-col :span="5">
                    <el-tag closable
                            @close="removeRightById(scope.row,item1.id)">{{item1.authName}}</el-tag><i class="el-icon-caret-right"></i>
                </el-col>
                <!-- 渲染二级和三级权限 -->
                <el-col :span="19">
                    <!-- 二级权限渲染 -->
                    <el-row :class="[i2 === 0 ? '':'bdtop','vcenter']"
                            v-for="(item2,i2) in item1.children"
                            :key="item2.id">
                    <el-col :span="6">
                        <el-tag type="success"
                                closable
                                @close="removeRightById(scope.row,item2.id)">{{item2.authName}}</el-tag><i class="el-icon-caret-right"></i>
                    </el-col>
                    <!-- 三级权限渲染 -->
                    <el-col :span="18">
                        <el-tag type="warning"
                                closable
                                @close="removeRightById(scope.row,item3.id)"
                                v-for="(item3) in item2.children"
                                :key="item3.id">{{item3.authName}}</el-tag>
                    </el-col>
                    </el-row>
                </el-col>
                </el-row>
            </template>
            </el-table-column>
            <el-table-column type="index"
                            label="#">
            </el-table-column>
            <el-table-column prop="roleName"
                            label="角色名称">
            </el-table-column>
            <el-table-column prop="roleDesc"
                            label="角色描述">
            </el-table-column>
            <el-table-column label="操作"
                            width="300px">
            <template slot-scope="scope">
                <!-- 编辑按钮 -->
                <el-button type="primary"
                        icon="el-icon-edit"
                        size="mini"
                        @click="showEditDialog(scope.row.id)">
                编辑
                </el-button>
                <!-- 删除按钮 -->
                <el-button type="danger"
                        icon="el-icon-delete"
                        size="mini"
                        @click="removeRolesById(scope.row.id)">
                删除
                </el-button>
                <!-- 分配权限按钮 -->
                <el-tooltip effect="dark"
                            content="分配角色"
                            placement="top"
                            :enterable='false'>
                <el-button type="warning"
                            icon="el-icon-setting"
                            size="mini"
                            @click="showSetRightDialog(scope.row)">
                    分配权限
                </el-button>
                </el-tooltip>
            </template>
            </el-table-column>
        </el-table>
        </el-card>

    </div>
</template>

<script>
import {userRoles,addRoles} from "@/api/rights"
    export default {
        data(){
            return{
                //角色列表
                rolesList:[],
                //控制添加角色对话框的显示与隐藏
                dialogFormVisible:false,
                //添加角色表单数据
                addForm:{
                    roleName:'',
                    roleDesc:'',
                }
            }
        },
        created(){
            this.getRolesList()
        },
        methods:{
            //获取角色列表
            async getRolesList(){
                const res = await userRoles()
                console.log(res);
                if(res.meta.status !== 200) return this.$message.error('获取角色列表失败！')
                this.rolesList = res.data
            },
        }
    }
</script>

<style lang="scss" scoped>

</style>